const BaseIpcHandler = require('../BaseIpcHandler');

class GetPythonEnvsHandler extends BaseIpcHandler {
    async handle(event, params) {
        // 解析参数
        // console.log('>> GetPythonEnvsHandler params = ', params);

        // 业务逻辑
        let result = null;
        try {
            let envlist = await this.app.pythonEnv.getEnvList();
            // console.log(`python Environments =  `, envlist);
            result = { code: 0, msg: envlist };
        } catch (error) {
            console.error('Get Python Environments Failed! Error:', error.message);
            result = { code: -1, msg: error.message };
        }

        // 返回结果
        if (event.from === 'localserver') {
            event.resp.send(result);
        } else {
            return result;
        }
    }
}

module.exports = GetPythonEnvsHandler;
